package com.itheima.controller;

import com.itheima.pojo.Order;
import com.itheima.pojo.Orderdetail;
import com.itheima.pojo.Result;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 根据订单号查询订单信息和下单人信息(一对一)
     * @param orderNumber
     * @return
     */
    @GetMapping("/{orderNumber}")
    public Result getOrderByNumber(@PathVariable String orderNumber){
        Order order = orderService.getOrderByNumber(orderNumber);
        return Result.success(order);
    }

    /**
     * 根据订单号查询订单详情和商品信息(多对多)
     * @param orderNumber
     * @return
     */
    @GetMapping
    public Result getOrderAndDetail(String orderNumber){
        List<Orderdetail> orderdetailList = orderService.getOrderAndDetail(orderNumber);
        return Result.success(orderdetailList);
    }
}
